<template>
  <div style='margin-bottom: 100px'>
  <el-form :model="headerlist" :rules='rules' ref='form' label-width="10px" label-position="top">

    <!-- 客户信息 -->
      <el-row class="container" STYLE="margin-top:20PX;">
          <!-- <h3 style="margin-bottom:20px;">客户信息མཁོ་མཁན་ཆ་འཕྲིན་ </h3> -->
            <h3 style="margin-bottom:20px;">客户信息 </h3>
          <el-col :span="12">
              <el-form-item label='出库单号：' prop='orderNumber'>
                <el-input placeholder="请输入内容" v-model="headerlist.orderNumber"  style="width:300px"></el-input>
              </el-form-item>
              <el-form-item label="客户名称：" @click.native="select" prop='clientName'>
                <div slot="label">客户名称</div>
                <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">མཁོ་མཁན་ཆ་འཕྲིན་ </div>
                  <el-input placeholder="请输入内容" v-model="headerlist.clientName"  style="width:300px"></el-input>
              </el-form-item>
              <el-form-item label="销售员：" prop='salesperson'>
                <div slot="label">销售员</div>
                <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">ཚོང་མཁན་  </div>
                  <template>
                      <el-select
                          v-model="headerlist.salesperson"
                          style="width:300px"
                          placeholder="请选择"
                      >
                          <el-option
                              v-for="item in userlist"
                              :key="item.id"
                              :label="item.name"
                              :value="item.name"
                          ></el-option>
                      </el-select>
                  </template>
              </el-form-item>
              <el-form-item v-if="showSH" label="收货人：" prop='consignee'>
                <div slot="label">收货人</div>
<!--                <div slot="label" style="line-height: 0px">མཛོད་བཅུག་དུས་ཚོད་ </div>-->
                  <el-input style="width:300px;" v-model="headerlist.consignee"></el-input>
              </el-form-item>
              <el-form-item v-if="showSH" label="收货地址：" prop='address'>
                <div slot="label">收货地址</div>
<!--                <div slot="label" style="line-height: 0px">མཛོད་བཅུག་དུས་ཚོད་ </div>-->
                  <el-input style="width:300px;" v-model="headerlist.address"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="10">
              <el-form-item label='仓库：' prop='warehouse'>
                  <el-select v-model="headerlist.warehouseId" style="width:300px" @change='wareHouseChange'>
                      <el-option v-for='item in warehouseList' :key='item.id' :label='item.warehouse' :value='item.id'></el-option>
                  </el-select>
              </el-form-item>
			  <el-form-item label="交货时间：" prop='deliverTime'>
          <div slot="label">交货时间</div>
          <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">ཚོང་ཟོག་རྩིས་སྤྲོད་ཀྱི་དུས་ཚོད་ </div>
				  <el-date-picker
					  v-model="headerlist.deliverTime"
					  type="date"
					  value-format="yyyy-MM-dd"
					  placeholder
					  style="width:300px"
				  ></el-date-picker>
			  </el-form-item>
              <el-form-item label="订单来源：" prop='source'>
                <div slot="label">订单来源</div>
                <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">མངག་ཐོ་ཡོང་ཁུངས་ </div>
                  <el-select v-model="headerlist.source" placeholder="请选择" style="width:300px;">
                      <el-option label="线下" value="线下"></el-option>
                      <el-option label="淘宝" value="淘宝"></el-option>
					  <el-option label="京东" value="京东"></el-option>
					  <el-option label="微信" value="微信"></el-option>
					  <el-option label="微店" value="微店"></el-option>
                  </el-select>
              </el-form-item>
              <el-form-item v-if="showSH" label="收货电话：" prop='phone'>
                <div slot="label">收货电话</div>
<!--                <div slot="label" style="line-height: 0px">མཛོད་བཅུག་དུས་ཚོད་ </div>-->
                  <el-input style="width:300px;" v-model="headerlist.phone"></el-input>
              </el-form-item>
          </el-col>
      </el-row>


    <!-- 订单信息 -->
    <el-form class="order">
      <el-row class="container" STYLE="margin-top:20PX;">
        <h3 style="margin-bottom:20px;">订单明细</h3>
          <el-table
            :data="orderDetailedList"
            border
            style="margin-top:20px;"
            ref="multipleTable"
            :summary-method="getSummaries"
			show-summary
            header-cell-class-name="table-header"
            class="order-table"
          >
            <!-- <el-table-column label="产品名称ཐོན་རྫས་ཀྱི་མིང་ "> -->
                <el-table-column label="产品名称་ ">
              <template slot-scope="scope">
                <el-form-item @click.native="select1(scope.$index, scope.row)" prop='name'>
                  <el-input  placeholder="请输入内容" v-model="scope.row.name" ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="specs" label="规格ཚད་གཞི་ "></el-table-column>
            <el-table-column prop="batch" label="批号ཆོག་མཆན་ཨང་གྲངས། "></el-table-column>
            <el-table-column prop="number" label="数量གྲངས་འབོར་ "> -->
                <el-table-column prop="specs" label="规格"></el-table-column>
            <el-table-column prop="batch" label="批号 "></el-table-column>
            <el-table-column prop="number" label="数量">
              <template slot-scope="scope">
                <el-form-item prop='number'>
					 <el-input  placeholder="请输入内容" v-model="scope.row.number" @change="addup(scope.$index, scope.row)"></el-input>
                  <!-- <el-input-number v-model="ruleForm1.num" controls-position="right"  :min="1" :max="10"></el-input-number> -->
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="unit" label="单位འཇལ་བྱེད། "></el-table-column> -->
             <el-table-column prop="unit" label="单位"></el-table-column>
              <el-form-item prop='price'>
                <el-table-column prop="price" label="单价(元)">
                  <template slot-scope="scope">
                        <el-input  placeholder="请输入内容" v-model="scope.row.price" @change="addup(scope.$index, scope.row)"></el-input>
                      <!-- <el-input-number v-model="ruleForm1.num" controls-position="right"  :min="1" :max="10"></el-input-number> -->
                  </template>
                </el-table-column>
              </el-form-item>
            <el-table-column prop="totalPrice" label="小计(元)"></el-table-column>

            <!-- <el-table-column label="操作" width="150" align="center">
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        @click="handleSelect(scope.$index, scope.row)"
                    >选择</el-button>
                </template>
            </el-table-column> -->
          </el-table>
          <el-col class="add" @click.native="addProduct">+添加产品</el-col>
      </el-row>

    </el-form>


    <!-- 财务信息 -->
      <el-row class="container" STYLE="margin:20PX 0 40px 0 ;">
          <h3 style="margin-bottom:20px;">财务信息</h3>
          <el-col :span="12">
              <el-form-item label="发票信息：" prop='invoiceType'>
                <div slot="label">发票信息</div>
                <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">འཛིན་ཤོག་ཆ་འཕྲིན་ </div>
                  <el-select v-model="headerlist.invoiceType" @change="showForm" placeholder="请选择" style="width:300px;">
                      <el-option :label="v" :value="v" v-for="(v,i) in ruleForm2.fapiaos" :key="i"></el-option>
                  </el-select>
              </el-form-item>
              <el-form-item v-if="showFormItem == 1 || showFormItem == 2" label="纳税人识别号：" prop='invoiceCode'>
                  <el-input placeholder="请输入内容" v-model="headerlist.invoiceCode"  style="width:300px"></el-input>
              </el-form-item>
              <el-form-item v-if="showFormItem == 2" label="地址：" prop='invoiceAddress'>
                  <el-input placeholder="请输入内容" v-model="headerlist.invoiceAddress"  style="width:300px"></el-input>
              </el-form-item>
              <el-form-item v-if="showFormItem == 2" label="开户银行：" prop='invoiceBank'>
                  <el-input placeholder="请输入内容" v-model="headerlist.invoiceBank"  style="width:300px"></el-input>
              </el-form-item>
              <!-- <el-form-item v-show="showFormItem == 2" label="付款情况："> -->
              <el-form-item label="付款情况：" prop='payState'>
                <div slot="label">付款情况</div>
<!--                <div slot="label" style="line-height: 0px">མཛོད་བཅུག་དུས་ཚོད་ </div>-->
                  <el-select v-model="headerlist.payState" placeholder="请选择" style="width:300px;">
                      <el-option :label="v" :value="v" v-for="(v,i) in ruleForm2.pays" :key="i"></el-option>
                  </el-select>
              </el-form-item>
              <!-- <el-form-item v-show="showFormItem == 2" label="付款金额："> -->
              <el-form-item label="付款金额：" prop='payAmount'>
                <div slot="label">付款金额</div>
                <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">དངུལ་སྤྲོད་པའི་དངུལ་གྲངས་ </div>
                  <el-input placeholder="请输入内容" style="width:300px;" v-model="headerlist.payAmount"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="10">
              <el-form-item v-if="showFormItem == 1 || showFormItem == 2" label="公司名称：" prop='invoiceRise'>
                  <el-input placeholder="请输入内容" style="width:300px;" v-model="headerlist.invoiceRise"></el-input>
              </el-form-item>
              <el-form-item v-if="showFormItem == 2" label="电话号码：" prop='invoicePhone'>
                  <el-input placeholder="请输入内容" style="width:300px;" v-model="headerlist.invoicePhone"></el-input>
              </el-form-item>
              <el-form-item v-if="showFormItem == 2" label="开户名称：" prop='invoiceName'>
                  <el-input placeholder="请输入内容" style="width:300px;" v-model="headerlist.invoiceName"></el-input>
              </el-form-item>
              <el-form-item v-if="showFormItem == 2" label="银行账号：" prop='invoiceBankCode'>
                  <el-input placeholder="请输入内容" style="width:300px;" v-model="headerlist.invoiceBankCode"></el-input>
              </el-form-item>
              <!-- <el-form-item v-show="showFormItem == 2" label="付款方式："> -->
              <el-form-item label="付款方式：" prop='payType'>
                <div slot="label">付款方式</div>
                <div slot="label" style="line-height: 0px" v-show="$store.state.zangw=='1'">དངུལ་སྤྲོད་སྟངས་ </div>
                <el-select v-model="headerlist.payType" placeholder="请选择" style="width:300px;">
                    <el-option :label="v" :value="v" v-for="(v,i) in ruleForm2.paytypes" :key="i"></el-option>
                </el-select>
              </el-form-item>
          </el-col>
      </el-row>


      <el-form-item class="footerFixed" v-if="type != 'detail'" label-width="0px">
          <div class='fixed'>
              <el-button class='theme-button' style="margin:0 20px;" @click="save">提交</el-button>
              <el-button @click="goback">返回</el-button>
          </div>
      </el-form-item>
	  <el-form-item class="footerFixed" v-else label-width="0px">
          <div class='fixed'>
              <el-button @click="goback">返回</el-button>
          </div>
	  </el-form-item>


  </el-form>
  <el-dialog title="选择用户" :visible.sync="dialogTableVisible">
          <el-form :model="ruleForm" label-position="left" >
              <el-row :gutter="40">
                  <el-col :span="11">
                      <el-form-item label="搜索" prop='query'>
                          <el-input v-model="query" @change="getlist" placeholder="用户名称/联系人" style="width:200px;"></el-input>
                      </el-form-item>
                  </el-col>

              </el-row>


          </el-form>
          <el-table
              :data="tableData"
              border
              style="margin-top:20px;"
              ref="multipleTable"
              header-cell-class-name="table-header"
          >
              <el-table-column prop="clientName" sortable label="客户名称"></el-table-column>
              <el-table-column prop="area" sortable label="所在地址"></el-table-column>
              <el-table-column prop="userName" sortable label="联系人"></el-table-column>
              <el-table-column prop="phone" sortable label="手机号码"></el-table-column>

              <el-table-column label="操作" width="150" align="center">
                  <template slot-scope="scope">
                      <el-button
                          type="text"
                          @click="handleSelect(scope.$index, scope.row)"
                      >选择</el-button>
                  </template>
              </el-table-column>
          </el-table>
          <el-pagination
              layout="total, prev, pager, next, jumper"
              :page-size="pagesize"
              :current-page.sync="currentPage"
              :total="total"
              @current-change="handleCurrentChange"
              style="margin-top:20px"
          ></el-pagination>
      </el-dialog>
  <el-dialog title="选择产品" :visible.sync="dialogTableVisible1">
          <el-form :model="ruleForm1" label-position="left" label-width="100px">
          </el-form>
          <el-table
              :data="ProductList"
              border
              style="margin-top:20px;"
              ref="multipleTable"
              header-cell-class-name="table-header"
          >
              <!-- <el-table-column prop="productName" sortable label="产品名称ཐོན་རྫས་ཀྱི་མིང་ "></el-table-column>
              <el-table-column prop="batch" sortable label="批号ཆོག་མཆན་ཨང་གྲངས། "></el-table-column>
              <el-table-column prop="specs" sortable label="规格ཚད་གཞི་ "> -->
              <el-table-column prop="productName" sortable label="产品名称"></el-table-column>
              <el-table-column prop="batch" sortable label="批号"></el-table-column>
              <el-table-column prop="specs" sortable label="规格">
                  <template slot-scope="scope">
                      {{scope.row.specs}}{{scope.row.specsUnit}}
                  </template>
              </el-table-column>
              <!-- <el-table-column prop="batch" sortable label="数量གྲངས་འབོར་ "> -->
              <el-table-column prop="batch" sortable label="数量">
                  <template slot-scope="scope">
                      <!-- {{scope.row.surplus}}{{scope.row.oneunit}} -->
                      {{scope.row.number}}{{scope.row.oneunit}}
                  </template>
              </el-table-column>

              <el-table-column label="操作" width="150" align="center">
                  <template slot-scope="scope">
                      <el-button
                          type="text"
                          @click="handleSelect1(scope.$index, scope.row)"
                      >选择</el-button>
                  </template>
              </el-table-column>
          </el-table>
          <el-pagination
              layout="total, prev, pager, next, jumper"
              :page-size="pagesize"
              :current-page.sync="currentPage1"
              :total="total1"
              @current-change="handleCurrentChange1"
              style="margin-top:20px"
          ></el-pagination>
      </el-dialog>

  </div>
</template>


<script>
	import { client_findByList,user_findByAll,storage_findByList,order_save,order_findById,order_update,base_findByPositionList } from "@/request/api"
	 import {CodeToText} from 'element-china-area-data'
export default {
	  data() {
			return {
                rules:{
                    orderNumber:[{ required: true, message: '请输入订单编号', trigger: 'blur' }],
                    clientName:[{ required: true, message: '请输入客户名称', trigger: 'blur' }],
                    salesperson:[{ required: true, message: '请输入销售人员', trigger: 'blur' }],
                    consignee:[{ required: true, message: '请输入收货人', trigger: 'blur' }],
                    address:[{ required: true, message: '请输入收货地址', trigger: 'blur' }],
                    warehouse:[{ required: true, message: '请输入收货仓库', trigger: 'blur' }],
                    deliverTime:[{ required: true, message: '请输入交货日期', trigger: 'blur' }],
                    source:[{ required: true, message: '请输入订单来源', trigger: 'blur' }],
                    phone:[{ required: true, message: '请输入收货电话', trigger: 'blur' }],
                    name:[{ required: true, message: '请输入产品名字', trigger: 'blur' }],
                    number:[{ required: true, message: '请输入产品数量', trigger: 'blur' }],
                    price:[{ required: true, message: '请输入产品价格', trigger: 'blur' }],
                    invoiceType:[{ required: true, message: '请输入发票类型', trigger: 'blur' }],
                    invoiceCode:[{ required: true, message: '请输入发票代码', trigger: 'blur' }],
                    invoiceAddress:[{ required: true, message: '请输入发票地址', trigger: 'blur' }],
                    invoiceBank:[{ required: true, message: '请输入开户银行', trigger: 'blur' }],
                    payType:[{ required: true, message: '请输入付款方式', trigger: 'blur' }],
                    payAmount:[{ required: true, message: '请输入付款金额', trigger: 'blur' }],
                    payState:[{ required: true, message: '请输入付款状态', trigger: 'blur' }],
                },
                warehouseList:[],
				orderDetailedList:[{
					name:'',
					specs:'',
					id:'',
					batch:'',
					storageId:'',
					number:'',
					totalPrice:''
				}],
				  query:'',
				  // 客户信息
				  form1:{

				  },
				  ruleForm:{
					uername:''
				  },
				  dialogTableVisible:false,
				  tableData:[{}],
				  pagesize:10,
				  currentPage:1,
				  total:1,
				  currentPage1:1,
				  total1:1,
				  showSH:false,

				  // 订单明细
				  ruleForm1:{
					username:''
				  },
				  dialogTableVisible1:false,

				  // 财务信息
				  ruleForm2:{
					username:'',
					fapiao:'',
					fapiaos:["不开发票","增值税普通发票","增值税专用发票"],
					pay:'',
					pays:["未付款","已付首款","已付全款",],
					paytype:'',
					paytypes:["现金","银行转账","微信","支付宝"]
				  },
				  showFormItem:0,
				  headerlist:{},
				  userlist:'',
				  ProductList:[],
				  index:'',
          id:'',
          totalAmount: '',
          type:'',

          orderNo: '',
          invoiceId: '',
			}
	  },
	  mounted() {
          this.getWarehouse()
     this.id = this.$route.query.id
     this.orderNo = this.$route.query.orderNo
     this.type = this.$route.query.type
		  if(this.id != undefined){
			  this.getdetails()
		  }
		 this.init()
		 this.getUserList()
		 this.getProductList()

	  },
	  methods: {
          wareHouseChange(v){
              this.headerlist.warehouseId = v
              this.headerlist.warehouse = this.warehouseList.filter(item=>item.id == v)[0].warehouse
          },
          async getWarehouse(){
            const res = await base_findByPositionList({pageno:1,pagesize:1000})
            if(res && res.rows.length > 0){
                this.warehouseList = res.rows
            }
          },
      getSummaries(param) {
				const { columns, data } = param;
        console.log(data)
				const sums = [];
				let values = []
				columns.forEach((column, index) => {
					if (index === 0) {
						sums[index] = '合计';
						return;
					}
					if(column.property == "totalPrice"){
            console.log(data)
						values = data.map(item => Number(item.totalPrice))
            // console.logS
					}
					if(column.property == "totalPrice") {
						sums[index] = values.reduce((prev,curr) => {
							const value = Number(curr)
							if(!isNaN(value)){
                this.totalAmount = prev + curr
                return prev + curr
							}else{
                return prev
							}
						},0)
						sums[index]
					} else {
						sums[index] = ""
					}
				});
				// this.totalMoney = sums[3]
        // console.log(sums)
        return sums;
			  },
		  goback(){
			this.$router.go(-1)
		  },
		  getdetails(){
        order_findById(this.id).then((res)=>{
          this.headerlist = res.data.order
          this.orderDetailedList = res.data.details
          this.invoiceId = res.data.order.invoiceId
          this.showSH  =true

          if(res.data.order.payState == 0){
            this.headerlist.payState = '未付款'
          }else if(res.data.order.payState == 1){
            this.headerlist.payState = '已付首款'
          }else if(res.data.order.payState == 2){
            this.headerlist.payState = '已付全款'
          }

          if(res.data.order.invoiceId == 0){
            this.headerlist.invoiceType = '不开发票'
            this.showFormItem = 0
          }else if(res.data.invoice.type == '1'){
            this.headerlist.invoiceType = '增值税普通发票'
            this.headerlist.invoiceCode = res.data.invoice.invoiceCode
            this.headerlist.invoiceRise = res.data.invoice.invoiceRise
            this.showFormItem = 1
          }else if(res.data.invoice.type == '2'){
            this.headerlist.invoiceType = '增值税专用发票'
            this.headerlist.invoiceAddress = res.data.invoice.invoiceAddress
            this.headerlist.invoiceBank = res.data.invoice.invoiceBank
            this.headerlist.invoiceBankCode = res.data.invoice.invoiceBankCode
            this.headerlist.invoiceCode = res.data.invoice.invoiceCode
            this.headerlist.invoiceName = res.data.invoice.invoiceName
            this.headerlist.invoicePhone = res.data.invoice.invoicePhone
            this.headerlist.invoiceRise = res.data.invoice.invoiceRise
            this.showFormItem = 2
          }
        })
		  },
		  save(){
              this.$refs.form.validate((valid) => {
                  if(valid){
                      console.log(valid,'验证');
                      this.headerlist.orderDetailedList = this.orderDetailedList
                      this.headerlist.deliverState = 0
                      this.headerlist.totalAmount = this.totalAmount
                      this.headerlist.id = ''

                      if(this.headerlist.invoiceType == '不开发票'){
                        this.headerlist.invoiceId = '0'
                      } else {
                        this.headerlist.invoiceId = ''
                      }
                      // console.log(this.totalAmount,'111')
                      const dingdan = {"order": {},"details": [],"invoice": {}}
                            dingdan.details = this.headerlist.orderDetailedList
                            if(this.id != undefined){
                              dingdan.order.id = this.id
                            } else {
                              dingdan.order.id = ''
                            }
                            if(this.headerlist.invoiceType == '增值税普通发票') dingdan.invoice.type = '1'
                            if(this.headerlist.invoiceType == '增值税专用发票') dingdan.invoice.type = '2'
                            dingdan.invoice.invoiceRise = this.headerlist.invoiceRise
                            dingdan.invoice.invoiceCode = this.headerlist.invoiceCode
                            dingdan.invoice.invoicePhone = this.headerlist.invoicePhone
                            dingdan.invoice.invoiceAddress = this.headerlist.invoiceAddress
                            dingdan.invoice.invoiceName = this.headerlist.invoiceName
                            dingdan.invoice.invoiceBank = this.headerlist.invoiceBank
                            dingdan.invoice.invoiceBankCode = this.headerlist.invoiceBankCode
                            dingdan.invoice.cash = this.headerlist.payAmount
                            dingdan.order.orderNumber = this.headerlist.orderNumber
                            dingdan.order.warehouse = this.headerlist.warehouse
                            //付款金额不能大于总金额
                            if(dingdan.invoice.cash > this.totalAmount){
                              this.$notify({
                                title: '提示',
                                message: '付款金额不得大与总金额',
                                type: 'success',
                                duration: 1000
                              });
                              return
                            }
                            if(this.headerlist.payState == '未付款') dingdan.order.payState = 0
                            if(this.headerlist.payState == '已付首款') dingdan.order.payState = 1
                            if(this.headerlist.payState == '已付全款') dingdan.order.payState = 2
                            dingdan.order.deliverState = this.headerlist.deliverState
                            dingdan.order.clientId = this.headerlist.clientId
                            dingdan.order.clientName = this.headerlist.clientName
                            dingdan.order.deliverTime = this.headerlist.deliverTime
                            dingdan.order.salesperson = this.headerlist.salesperson
                            dingdan.order.source = this.headerlist.source
                            dingdan.order.consignee = this.headerlist.consignee
                            dingdan.order.phone = this.headerlist.phone
                            dingdan.order.address = this.headerlist.address
                            if(this.invoiceId != '' && this.ruleForm.invoiceType != '不开发票') {
                              dingdan.order.invoiceId = this.invoiceId
                            }else {
                              dingdan.order.invoiceId = this.headerlist.invoiceId
                            }
                            dingdan.order.payType = this.headerlist.payType
                            dingdan.order.payAmount = this.headerlist.payAmount
                            dingdan.order.totalAmount = this.headerlist.totalAmount
                            if(this.orderNo != ''){
                              dingdan.order.orderNo = this.orderNo
                            } else {
                              dingdan.order.orderNo = ''
                            }
                            dingdan.order.logistics = ''
                            dingdan.order.receiveTime = ''

                          order_save(dingdan).then((res)=>{
                          this.$notify({
                              title: '提示',
                              message: '保存成功',
                              type: 'success',
                              duration: 1000
                          });
                            this.$router.go(-1);
                          })
                  }
              })

		  },
		  addup(index,row){
              console.log(row);
        var m=0,s1=row.price,s2=row.number
        try{m+=s1.split(".")[1].length}catch(e){}
        try{m+=s2.split(".")[1].length}catch(e){}
        row.totalPrice = Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
		  },

		  addProduct(){
			  // console.log(111)
			this.orderDetailedList.push({name:'',
				specs:'',
				id:'',
				batch:'',
				storageId:'',
				number:'',
				totalPrice:''
			})
		  },
		  // 获取 产品表
		  getProductList(){
			  let data = {
				  page:this.currentPage1
			  }
			 storage_findByList(data).then((res)=>{

				 this.ProductList = res.rows
				 // console.log(this.ProductList)
				 this.total1 = res.total
				 for(var i=0;i<this.ProductList.length;i++){
          var r = this.ProductList[i].specsUnit;
          var site = r.lastIndexOf('/');
          this.ProductList[i].oneunit = r.substring(site + 1);

					//  var st = this.ProductList[i].specsUnit.substr(this.ProductList[i].specsUnit.lastIndexOf('/', this.ProductList[i].specsUnit.lastIndexOf('/') - 1) + 1);
					//  var str = st.lastIndexOf("\/")
					//  this.ProductList[i].oneunit  = st.substring(0,str)
					 // this.ProductList[i].oneunit = this.ProductList[i].specsUnit.substring(this.ProductList[i].specsUnit.lastIndexOf("\/")+1,this.ProductList[i].specsUnit.length)

				 }
        //  console.log()
			 })
		  },
		  // 获取员工
		  getUserList(){
			  user_findByAll("").then((res)=>{
				  this.userlist = res.data
			  })
		  },

		    getlist(){
				this.init()
			},
			// 获取客户信息
			init(){
				client_findByList({page:this.currentPage,query:this.query}).then((res)=>{
					this.tableData = res.rows
					this.total = res.total
					for (let i = 0; i < this.tableData.length; i++) {
						 var list = this.tableData[i].area.split(",")
						 var arr = ""
						 for (let k = 0; k < list.length; k++) {
							 arr += CodeToText[list[k]] + "/"
						 }
					    this.tableData[i].area = arr.substr(0,arr.length-1)
					}
				})
			},

			// 客户信息
			handleSelect(index,row){
				this.showSH = true
				this.dialogTableVisible = false
				this.headerlist.clientId = row.id
				this.headerlist.clientName = row.clientName
				this.headerlist.consignee = row.userName
				this.headerlist.phone = row.phone
				this.headerlist.address = row.address
			},
			select(){
			  this.dialogTableVisible = true
			},
			handleCurrentChange(val){
				this.currentPage = val
				this.init()
			},
			handleCurrentChange1(val){
				this.currentPage1 = val
				this.getpProductList()
			},
			// 订单信息
			handleSelect1(index,row){
			  this.dialogTableVisible1 = false
			  this.orderDetailedList[this.index].name = row.productName
			  this.orderDetailedList[this.index].specs = row.specs + row.specsUnit
			  this.orderDetailedList[this.index].batch = row.batch
			  this.orderDetailedList[this.index].sourceBatch = row.sourceBatch
			  this.orderDetailedList[this.index].number = row.number
			  this.orderDetailedList[this.index].id = row.id
			  this.orderDetailedList[this.index].unit = row.oneunit
			  this.orderDetailedList[this.index].orderId = ''
			  this.orderDetailedList[this.index].relateId = row.id
			  // this.orderDetailedList[this.index].price = row.oneunit
			  this.orderDetailedList[this.index].warehouseName = row.warehouseName
			  // console.log(this.orderDetailedList)
			  // Vue.set(this.orderDetailedList)
			},

			select1(index,row){
			    this.dialogTableVisible1 = true
				this.index = index
			},

			// 财务信息
			showForm(){
				  let obj = this.headerlist
				  if(obj.invoiceType == '不开发票' || obj.invoiceType == null){
					this.showFormItem = 0
				  }else if(obj.invoiceType == '增值税普通发票'){
					this.showFormItem = 1
				  }else if(obj.invoiceType == '增值税专用发票'){
					this.showFormItem = 2
				  }
			 }
		  },
	}
</script>



<style  scoped>
/deep/.el-form-item__label{
    line-height: initial !important;
}
  /* .containers{
    padding: 15px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 5px;
  } */
  .el-pagination{
      text-align: center;
  }
  .add{
    background-color: rgba(235, 245, 255, 1);
    border: 1px dotted lightgray;
    color: #333;
    margin: 10px 0 0 0;
    padding: 10px 0;
    text-align: center;
    cursor: pointer;
  }
  .order .order-table .el-form-item{
    margin-bottom: 0;
  }
</style>

